package com.atzxh.guigu.netty.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @author 小红同学
 * @date 2023-05-08-14:24
 * @description    使用transferFrom快速拷贝
 */
public class NIOFileChannel04 {
    public static void main(String[] args) throws Exception {

        // 创建流
        FileInputStream fileInputStream = new FileInputStream("file01.txt");
        FileOutputStream fileOutputStream = new FileOutputStream("file03.txt");

        // 获取各个流的通道
        FileChannel src = fileInputStream.getChannel();
        FileChannel dest = fileOutputStream.getChannel();

        // 使用transferForm完成拷贝
        dest.transferFrom(src,0,src.size());

        // 关闭流
        src.close();
        dest.close();
        fileInputStream.close();
        fileOutputStream.close();
    }
}
